package com.xb.system.controller;

import com.xb.common.helper.JwtHelper;
import com.xb.common.result.Result;
import com.xb.model.vo.LoginVo;
import com.xb.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 后台登录登出
 * </p>
 */
//@Api(tags = "后台登录管理")
//@RestController
//@RequestMapping("/admin/system/index")
public class IndexController {

    @Resource
    private SysUserService sysUserService;




    /**
     * 登录
     * @return
     */
    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo) {

        return sysUserService.loginCheck(loginVo);
    }

    /**
     * 获取用户信息
     * @return
     */
    @ApiOperation(value = "获取用户信息")
    @GetMapping("/info")
    public Result info(HttpServletRequest request) {
        String username = JwtHelper.getUsername(request.getHeader("token"));
        Map<String, Object> map = sysUserService.getUserInfo(username);
        return Result.ok(map);
    }

    /**
     * 退出
     * @return
     */
    @ApiOperation(value = "退出")
    @PostMapping("/logout")
    public Result logout(){
        return Result.ok();
    }

}
